package org.itboys.core.common;

/**
 * 作者：zzq
 * 时间：2018/8/24
 * 描述：自定义异常枚举
 *              code和value 保持唯一
 *             抛异常的格式   throw new ErrorException(ExceptionEnum.COMMENEXCPTION.getValue());
 */
public enum ExceptionEnum {
    EXCPTION("系统异常",-1),
    TOKENEXCPTION("签名错误",1),
    COMMENEXCPTION("常见错误",2),
    AUTHEXCPTION("没有权限",3),
    LOGIN_TYPE_EXCEPTION("登录类型错误",4),
    MOBILE_NOEXIST_TXCEPTION("手机号不存在",5),
    MOBILE_EQUAL_TXCEPTION("手机号不一致",6),
    MOBILE_HAS_BEEN_REGISTERED("手机号已经被注册",7),
    USER_NONENTITY("用户不存在",8),
    PASSWORD_ERROR("密码错误",9),
    USER_TYPE_ERROR("用户类型错误",10),
    MOBILE_FORMAT_ERROR("手机号格式有误",11),
    ZFB_NO_CONFIG_EXCEPTION("未配置支付宝支付信息",12),
    ZFB_PAY_EXCEPTION("支付宝预支付错误",13),
    MEMBER_WALLET_NO_EXCEPTION("用户余额不足",14),
    PARAM_NOT_ENOUGH_EXCEPTION("参数不足",15),
    VALIDATE_CODE_ERROR_EXCEPTION("验证码错误",16),
    DATA_ERROR_EXCEPTION("数据错误，请重新获取验证码。",17),
    GET_WALLET_RECORD_EXCEPTION("没有合法的钱包记录",18),
    GET_WALLET_EXCEPTION("获取钱包信息错误",19),
    USER_STATUS_EXCEPTION("用户状态异常",20),

    COUPON_USED_ERROR("优惠券使用异常",21),
    ADDRESS_EXCEPTION("地址错误",22),



    SEND_ORDER_STATUS_EXCEPTION("订单状态错误",101),
    SEND_ORDER_TRAY_NUM_EXCEPTION("托盘数量错误",102),
    SEND_ORDER_SEND_STORE_EXCEPTION("匹配派送仓库错误",103),
    SEND_ORDER_RECYCLE_STORE_EXCEPTION("匹配回收仓库错误",104),
    SEND_ORDER_SERVICE_EXCEPTION("归属供应商错误",105),
    SEND_ORDER_MEMBER_EXCEPTION("归属用户错误",106),
    SEND_ORDER_BUYOUT_NUM_EXCEPTION("买断数量错误",107),
    SEND_ORDER_RENEW_NUM_EXCEPTION("续费数量不足",108),
    SEND_ORDER_STORE_NUM_EXCEPTION("库存不足",109),


    RECYCLE_ORDER_STATUS_EXCEPTION("订单状态错误",201),
    RECYCLE_ORDER_MODEL_NUM_EXCEPTION("模板数量错误",202),
    RECYCLE_ORDER_STORE_EXCEPTION("匹配回收仓库错误",203),
    RECYCLE_ORDER_SERVICE_EXCEPTION("归属供应商错误",205),
    RECYCLE_ORDER_MEMBER_EXCEPTION("归属用户错误",206),
    RECYCLE_ORDER_MODEL_EXCEPTION("模板错误",207),
    RECYCLE_ORDER_TRAY_EXCEPTION("托盘错误",208),


    TRAY_APPLY_NUM_EXCEPTION("托盘申请数量错误",301),
    TRAY_STATUS_EXCEPTION("托盘状态错误",302),
    TRAY_MODEL_EXCEPTION("托盘模板错误",303),
    TRAY_SERVICE_EXCEPTION("托盘归属服务代理商错误",304),
    TRAY_STORE_EXCEPTION("托盘归属仓库错误",305),


    DISPATCH_STATE_EXCEPTION("调度单状态异常",401),
    DISPATCH_MODEL_EXCEPTION("调度模板异常",402)

    ;
    private int code;
    private String value;

    public static String exceptionStr(int code) {
        for (ExceptionEnum c : ExceptionEnum.values()) {
            if (c.getCode() == code) {
                return c.getValue();
            }
        }
        return null;
    }

    public static ExceptionEnum getExceptionEnum(String value) {
        for (ExceptionEnum c : ExceptionEnum.values()) {
            if (c.getValue() == value) {
                return c;
            }
        }
        return null;
    }

    ExceptionEnum(String value, int code) {
        this.value = value;
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
